const { getCardPackList } = require("../../api/cardApi");

Page({
  /**
   * 页面的初始数据
   */
  data: {
    cardData: [
      {
        title: "清洁VIP次卡",
        backgroundColor: "rgb(75, 215, 75)",
        many: "200",
      },
      {
        title: "清洁月卡",
        backgroundColor: "rgb(255, 161, 84)",
        many: "200",
      },
      {
        title: "清洁年卡",
        backgroundColor: "rgb(255, 103, 103)",
        many: "200",
      },
    ],
    cardList: [],
    cardJianjieData1: "",
    cardJianjieData2: "",
  },

  cardPackBack() {
    wx.switchTab({
      url: "../my/my",
    });
  },

  toCardDetail(e) {
    let gid = e.currentTarget.dataset.gid;
    wx.navigateTo({
      url: "../cardPackDetails/cardPackDetails?gid=" + gid,
    });
  },

  // 获取卡包列表
  async getCardPackListHandle(data) {
    const res = await getCardPackList(data);
    this.setData({
      cardList: res.data.data.list,
    });
    // console.log(res.data.data.list[0].content.replace(/<.*?>/gi, ""));
    console.log(res.data.data.list[0].content.split("</p>"));
    res.data.data.list[0].content
      .split("</p>")
      .slice(0, 2)
      .forEach((item, index) => {
        console.log(item, index);
        if (index === 0) {
          this.setData({
            cardJianjieData1: item.replace(/<.*?>/gi, ""),
          });
        }
        if (index === 1) {
          this.setData({
            cardJianjieData2: item.replace(/<.*?>/gi, ""),
          });
        }
      });

    console.log(this.data);
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {},

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    const token = wx.getStorageSync("token");
    this.getCardPackListHandle({ token });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
});
